<?php
require_once 'BaseController.php';

/**
 * 物件リクエスト検索クラス<br />
 *
 * @package    apamanshop
 * @author     SS山本
 * @copyright  コピーライト(要確認)
 */
class Search_RequestsearchController extends Search_BaseController
{
	
	public function indexAction()
	{
		$this->setMainTemplate('cms_search.tpl');
		/*
		 * 基本情報設定
		 */
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_BUKENREQUEST, "requestsearch");
		// 検索サブ区分
		$this->_data['srhtype_jyusyo']   = Apm_Config_Search::SRHTYPE_JYUSYO;
		$this->_data['srhtype_enseneki'] = Apm_Config_Search::SRHTYPE_ENSENEKI;

		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/common/add.css',array('type' => 'text/css','media' => 'all'));

        // 以下、検索画面によって条件分けする。
        // 都道府県検索画面の出力(初期呼び出し時)
		if (! $this->_model_common->checkvalue($this->_params, "PrefCd"))
    	{
			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の都道府県を選択してください。';
			// 手順画像
			$this->_data['omakase_image'] = '/images/search/common/img_step_easy01.jpg';
			$this->_data['step_image'] = '';
			$this->_data['step_alt'] = '';
			
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Seltodohuken2.js');

			$this->_main_helper = $this->_todohuken_request_easy_helper;
    	}
		// リクエスト対象店舗取得
		else{

			 // リクエスト店舗取得モデル
		    $this->_model_requesttenpo = new Search_Model_Requesttenpo();

			$this->_data['requestTenpo'] = array();
			$this->_data['requestTenpo'] = $this->_model_requesttenpo->getRequestTenpoSearch($this->_params);

			// モバイルAPIデータの作成
			$api_data = array();
			$api_data['count1'] = count($this->_data['requestTenpo']['area_tenpo']);
			$api_data['data1'] = $this->_data['requestTenpo']['area_tenpo'];

			$api_data['count2'] = count($this->_data['requestTenpo']['buken_tenpo']);
			$api_data['data2'] = $this->_data['requestTenpo']['buken_tenpo'];

			$this->_api_data = $api_data;
		}

// TODO 処理内容未決定
//		//町名検索画面で検索時
//		else
//		{
//        	$this->_data['main_block']  = $this->_main_helper->getBlock($this->_data);
//		}

		// 表示
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/requestsearch_easy.tpl';

	}

	// 市区町村検索画面の出力（都道府県検索画面で検索時）
	public function cityAction()
	{
		$this->setMainTemplate('cms_search.tpl');
		/*
		 * 基本情報設定
		 */
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_BUKENREQUEST, "requestsearch");
		// 検索サブ区分
		$this->_data['srhtype_jyusyo']   = Apm_Config_Search::SRHTYPE_JYUSYO;
		$this->_data['srhtype_enseneki'] = Apm_Config_Search::SRHTYPE_ENSENEKI;

		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/common/add.css',array('type' => 'text/css','media' => 'all'));

		
		if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
		         && ! $this->_model_common->checkvalue($this->_params, "CityCd") )
		{
			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の市区町村を選択してください。';
			// 手順画像
			$this->_data['omakase_image'] = '/images/search/common/img_omakase_title.jpg';
			$this->_data['step_image'] = '/images/search/common/step_b03_01.gif';
			$this->_data['step_alt'] = '市区町村を選ぶ。';
			
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Selsikucyoson.js');
			$this->addMetaJs($this->_aplbaseurl . 'js/search/jquery.switchHat.js');

            // 市区町村モデル
		    $this->_model_sikucyoson = new Search_Model_Selsikucyoson();

			$this->_data['selcity'] = array();
			//$this->_data['selcity'] = $this->_model_sikucyoson->generateShikucyosonRequestSql($this->_params);
			$this->_data['selcity'] = $this->_model_sikucyoson->getRequestShikucyosonData($this->_params);
	        // 表示用データに変換
        	$this->_model_sikucyoson->convertShikucyosonData($this->_data);
			// 不要なパラメータを削除
			if (isset($this->_params['SelTownKbn'])) {
				unset($this->_params['SelTownKbn']);
			}
			
			$this->_main_helper = $this->_shikucyoson_request_easy_helper;
		}
		// パラメータなしの場合にクエスト導入画面に遷移
		else{
			Apm_Util::redirect('/info/request/' );
		}
		
		// モバイルAPIデータの作成
		$this->mobileApiAct($this->_data['Mapping']);
		
		// 表示
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/requestsearch_easy.tpl';
	}

	// 沿線検索画面の出力（都道府県検索画面で検索時）
	public function ensenAction()
	{
		$this->setMainTemplate('cms_search.tpl');
		/*
		 * 基本情報設定
		 */
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_BUKENREQUEST, "requestsearch");
		// 検索サブ区分
		$this->_data['srhtype_jyusyo']   = Apm_Config_Search::SRHTYPE_JYUSYO;
		$this->_data['srhtype_enseneki'] = Apm_Config_Search::SRHTYPE_ENSENEKI;

		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/common/add.css',array('type' => 'text/css','media' => 'all'));

		if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
		         && ! $this->_model_common->checkvalue($this->_params, "RailCd") )
		{

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の沿線を選択してください。';
			// 手順画像
			$this->_data['omakase_image'] = '/images/search/common/img_omakase_title.jpg';
			$this->_data['step_image'] = '/images/search/common/step_b02_01.gif';
			$this->_data['step_alt'] = '沿線を選ぶ。';
			
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Selensen.js');
			$this->addMetaJs($this->_aplbaseurl . 'js/search/jquery.switchHat.js');

            // 沿線モデル
		    $this->_model_ensen = new Search_Model_Selensen();

			$this->_data['selensen'] = array();
			$this->_data['selensen'] = $this->_model_ensen->getRequestEnsenDataByMulti($this->_params);

			// 表示用データに変換
			$this->_model_ensen->convertEnsenDataByMulti($this->_data);

			$this->_main_helper = $this->_ensen_request_easy_helper;
		}		
		// パラメータなしの場合にクエスト導入画面に遷移
		else{
			Apm_Util::redirect('/info/request/' );
		}
		
		// モバイルAPIデータの作成
		$this->mobileApiAct($this->_data['Mapping']);
		
		// 表示
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/requestsearch_easy.tpl';
	}


	// 駅検索画面の出力（沿線検索画面で検索時）
	public function ekiAction()
	{
		$this->setMainTemplate('cms_search.tpl');
		/*
		 * 基本情報設定
		 */
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_BUKENREQUEST, "requestsearch");
		// 検索サブ区分
		$this->_data['srhtype_jyusyo']   = Apm_Config_Search::SRHTYPE_JYUSYO;
		$this->_data['srhtype_enseneki'] = Apm_Config_Search::SRHTYPE_ENSENEKI;

		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/common/add.css',array('type' => 'text/css','media' => 'all'));
				
		if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
		         && ! $this->_model_common->checkvalue($this->_params, "StCd") )
		{

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の駅を選択してください。';
			// 手順画像
			$this->_data['omakase_image'] = '/images/search/common/img_omakase_title.jpg';
			$this->_data['step_image'] = '/images/search/common/step_b02_02.gif';
			$this->_data['step_alt'] = '駅を選ぶ。';
			
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Seleki.js');
			$this->addMetaJs($this->_aplbaseurl . 'js/search/jquery.switchHat.js');

		    // 駅モデル
		    $this->_model_eki = new Search_Model_Seleki();

	        $this->_data['seleki'] = array();
			$this->_data['seleki'] = $this->_model_eki->getRequestEkiData($this->_params);

			// 表示用データに変換
			$this->_model_eki->convertEkiData($this->_data);

			$this->_main_helper = $this->_eki_request_easy_helper;

		}
		// パラメータなしの場合にクエスト導入画面に遷移
		else{
			Apm_Util::redirect('/info/request/' );
		}
		
		// モバイルAPIデータの作成
		$this->mobileApiAct($this->_data['Mapping']);
		
		// 表示
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/requestsearch_easy.tpl';		
	}

	// こだわり条件設定画面の出力
	public function jyokenAction()
	{
		$this->setMainTemplate('cms_search.tpl');
		/*
		 * 基本情報設定
		 */
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_BUKENREQUEST, "requestsearch");
		// 検索サブ区分
		$this->_data['srhtype_jyusyo']   = Apm_Config_Search::SRHTYPE_JYUSYO;
		$this->_data['srhtype_enseneki'] = Apm_Config_Search::SRHTYPE_ENSENEKI;

		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/common/add.css',array('type' => 'text/css','media' => 'all'));

		if (
				(  $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
				&& $this->_model_common->checkvalue($this->_params, "CityCd")
				&& ($this->_params["SelTownKbn"] == "0"
					|| ($this->_model_common->checkvalue($this->_params, "TownCd") && $this->_params["SelTownKbn"] == "1"))
				)
				||
				(  $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
				&& $this->_model_common->checkvalue($this->_params, "RailCd")
				&& $this->_model_common->checkvalue($this->_params, "StCd")
				)
			)
		{
			//DB問合せ：ご希望の検索条件一覧取得
		    $loader = new Zend_Application_Module_Autoloader(array(
				'namespace' => 'Rstobi',
				'basePath' => APPLICATION_PATH . '/modules/rstobi',
			));
			$this->_model = new Rstobi_Model_SearchDisplay();
			
			//検索条件（地域・沿線）の反映
			$this->_model->getSearchConditionChiikiEnsen($this->_params,$this->_data);
			//検索条件（基本条件）の反映
			$this->_model->getSearchConditionKihon($this->_params,$this->_data);
			//検索条件（こだわり条件）の反映
			$this->_model->getSearchConditionKodawari($this->_params,$this->_data);
			
			$this->_data['search_name'] = array();
			$conditions = $this->_model_common->getFormSearchName($this->_params, 1, '・');
			if (!empty($conditions['search_name'])) {
				foreach ($conditions['search_name'] as $searchName) {
					$this->_data['search_name'][] = $searchName;
				}
			}
			
			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の条件を選択してください。';
			// 手順画像
			$this->_data['omakase_image'] = '/images/search/common/img_omakase_title.jpg';
			if ($this->_params['SrhType']== Apm_Config_Search::SRHTYPE_JYUSYO){
				$this->_data['step_image'] = '/images/search/common/step_b03_02.gif';
			}else if($this->_params['SrhType'] == Apm_Config_Search::SRHTYPE_ENSENEKI){
				$this->_data['step_image'] = '/images/search/common/step_b02_03.gif';
			}
			$this->_data['step_alt'] = '条件を選ぶ。';
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/selcond2.js');
			$this->addMetaJs($this->_aplbaseurl . 'js/search/jquery.switchHat.js');
						
			// Hiddenタグ生成
			$hidden = array();
			$hidden['SrhKbn']      = $this->_params['SrhKbn'];
			$hidden['SrhType']     = $this->_params['SrhType'];
			$hidden['first_check'] = $this->_params['first_check'];
			$hidden['PrefCd']      = $this->_params['PrefCd'];
			if ($this->_model_common->checkvalue($this->_params, "CityCd")) {
				$hidden['CityCd']      = $this->_params['CityCd'];
				$hidden['SelTownKbn']  = $this->_params['SelTownKbn'];
			}
			if ($this->_model_common->checkvalue($this->_params, "TownCd")) {
				$hidden['TownCd']      = $this->_params['TownCd'];
			}
			if ($this->_model_common->checkvalue($this->_params, "RailCd")) {
				$hidden['RailCd']      = $this->_params['RailCd'];
			}
			if ($this->_model_common->checkvalue($this->_params, "StCd")) {
				$hidden['StCd']        = $this->_params['StCd'];
			}
			$this->_data['ReqHiddenTag'] = Apm_Util::generateHiddenTag($hidden);
			
			$this->_disabledLeftPanel = false;
			$this->_main_helper = $this->_selbasic_easy_helper;
			
			// モバイルAPIデータの作成
			$this->mobileApiAct($this->_data['search_name']);
		}
		// パラメータなしの場合にクエスト導入画面に遷移
		else{
			Apm_Util::redirect('/info/request/' );
		}

		// 表示
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/requestsearch_easy.tpl';
	}
}
?>